package com.kejiguan.ui.response;

import com.google.gson.annotations.Expose;
import com.kejiguan.ui.model.DisplayArea;
import com.kejiguan.ui.model.MenuItem;
import com.kejiguan.ui.model.ExhibitionNeItem;
import com.kejiguan.ui.model.SystemUser;
import com.kejiguan.ui.util.CacheDataUtil;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * Created by apple on 16/4/16.
 */
public class LoginResponse extends BaseResponse{

    @Expose
    private SystemUser sysUser;//登录用户对象
    @Expose
    private Map<String,List<ExhibitionNeItem>> exhibitionRecordMap;
    @Expose
    private List<MenuItem> menuList;

    private List<DisplayArea> displayAreas;

    private List<String> disPlayAreaIdNames=new ArrayList<>();


    public SystemUser getSysUser() {
        return sysUser;
    }

    public void setSysUser(SystemUser sysUser) {
        this.sysUser = sysUser;
    }

    public Map<String, List<ExhibitionNeItem>> getExhibitionRecordMap() {
        return exhibitionRecordMap;
    }

    public void setExhibitionRecordMap(Map<String, List<ExhibitionNeItem>> exhibitionRecordMap) {
        this.exhibitionRecordMap = exhibitionRecordMap;
    }

    public List<MenuItem> getMenuList() {
        return menuList;
    }

    public void setMenuList(List<MenuItem> menuList) {
        this.menuList = menuList;
    }


    public List<DisplayArea> getDisplayAreas() {
        return displayAreas;
    }

    public void setDisplayAreas(List<DisplayArea> displayAreas) {
        this.displayAreas = displayAreas;
    }

    public void initdisplayAreaDatas()
    {
        if (null!=exhibitionRecordMap)
        {
            if (null==displayAreas)
            {
                displayAreas=new ArrayList<>();
                Set<String> keys=exhibitionRecordMap.keySet();
                Iterator<String> stringIterator=keys.iterator();
                while (stringIterator.hasNext())
                {
                    String key=stringIterator.next();
                    disPlayAreaIdNames.add(key);
                    String[] mutyKeys=key.split("=");

                    DisplayArea displayArea=new DisplayArea();
                    displayArea.setDisplayId(mutyKeys[0]);
                    displayArea.setDisplayName(mutyKeys[1]);
                    displayArea.setExhibitionNeItems(exhibitionRecordMap.get(key));

                    displayAreas.add(displayArea);
                }
            }
        }

        CacheDataUtil.getInstance().setDisPlayAreaIdNames(disPlayAreaIdNames);
    }


    public void initMenus(SystemUser systemUser)
    {
        List<MenuItem> userMenus=new ArrayList<>();
        if (null!=menuList)
        {
            for (MenuItem menuItem:menuList)
            {
                if (menuItem.getParentId()!=0&&systemUser.getNavList().contains(String.valueOf(menuItem.getMenuId())))
                {
                    userMenus.add(menuItem);
                }
            }
            CacheDataUtil.getInstance().setMenuItems(userMenus);
        }

    }
}
